# -*- coding: utf-8 -*-
# @Time : 2024/6/10 16:25
# @Author  : lining
# @FileName: pageOpt.py
import time

from playwright.sync_api import Playwright, sync_playwright, Page, expect
import asyncio
from Core.elementOpt import Element

with sync_playwright() as p:
    browser = p.chromium.launch(headless=False)
    context = browser.new_context(storage_state=)
    page = context.new_page()
    context.storage_state()
    page.goto('https://www.baidu.com')
    ele = page.locator('a').first
    print(ele.count())
    page.get_by_placeholder('11').type()
    page.get_by_role().fill()
    a = page.frame(url='https://sahitest.com/demo/framesTest.htm')
    b = page.frame_locator('body > table > tbody > tr > td:nth-child(1) > a:nth-child(1)')
    ele = Element(page)
    ele.element_find_element(['role','input']).fill('1234')
    # page.get_by_role()
    page.fill('#userName', 'lntest@cms.cn')
    page.fill('#password', '2ws#ED4rf==!!')
    page.locator('button').click()
    page.mouse.move()
    page.click('button')
    time.sleep(2)
    print(context.storage_state(path='1.json'))
    a = page.evaluate('window.sessionStorage;')
    page.expect_file_chooser()
    page.locator('button').click()
    page.locator('button').hover()
    # page.wait_for_selector('text=登录成功！', timeout=5000)
    # a = page.evaluate('window.sessionStorage;')
    # # time.sleep(2)
    # print(type(a))
    # page.wait_for_selector()
    # page.frame_locator()
    b = page.frame_locator('#frameforlogin')
    a=page.frame(name='frameforlogin')
    print(expect(ele).to_have_js_property())
    ele = page.locator('text=登录成功1！')
    print(ele.count())
    page.close()

if __name__ == '__main__':
    print(11)